package com.woniu.microuserserver.utils;


import com.woniu.microcommonsserver.entity.RolePermEntity;
import com.woniu.microuserserver.bean.PremsOfRole;

import java.util.ArrayList;
import java.util.List;

public class MyArrayUtils {
    public static int sumArray(int[] ints){
        if (ints==null){
            return 0;
        }else{
            int sum = 0;
            for (int i = 0; i < ints.length; i++) {
                sum = sum + ints[i];
            }
            return sum;
        }
    };
    //将一个数值类型的权限对象转为集合类型
    public static PremsOfRole getPremOfRole(RolePermEntity rolePermEntity){
        PremsOfRole prems = new PremsOfRole();
        //转为集合
        if(rolePermEntity==null){
            return null;
        }
        Integer homePerm = rolePermEntity.getHomePerm();//
        List<Integer> hlist = getListByValue(homePerm);
        prems.setHps(hlist);
        Integer wi = rolePermEntity.getWkodmangePerm();
        List<Integer> wlist = getListByValue(wi);
        prems.setWps(wlist);
        Integer bi = rolePermEntity.getBusconfigPerm();
        List<Integer> blist = getListByValue(bi);
        prems.setBps(blist);
        Integer ui = rolePermEntity.getUsercentrePerm();
        List<Integer> ulist = getListByValue(ui);
        prems.setUps(ulist);
        return prems;
    }

    public static List<Integer> getListByValue(Integer i){
        ArrayList<Integer> list = new ArrayList();
        switch (i){
            case 0:
                break;
            case 1:
                list.add(1);
                break;
            case 2:
                list.add(2);
                break;
            case 3:
                list.add(1);
                list.add(2);
                break;
            case 4:
                list.add(4);
                break;
            case 5:
                list.add(1);
                list.add(4);
                break;
            case 6:
                list.add(2);
                list.add(4);
                break;
            case 7:
                list.add(1);
                list.add(2);
                list.add(4);
                break;
        }
        return list;
    }

}
